﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace GameFlowManager.Menus
{
	public class FluentMenuConstructor
	{
		public class FluentMenuItemConstructor
		{
			#region Variables

			private FluentMenuConstructor _menuConstructor;
			private MenuItem _item;

			#endregion

			#region Constructors

			internal FluentMenuItemConstructor(FluentMenuConstructor menuConstructor)
			{
				_menuConstructor = menuConstructor;
				_item = new MenuItem();
			}

			#endregion

			#region Methods

			public FluentMenuItemConstructor SetIcon(Texture2D icon)
			{
				_item.Icon = icon;
				return this;
			}

			public FluentMenuItemConstructor SetIcon(string textureAsset)
			{
				_item.Icon = _menuConstructor.Game.Content.Load<Texture2D>(textureAsset);
				return this;
			}

			public FluentMenuItemConstructor SetName(string name)
			{
				_item.Name = name;
				return this;
			}

			public FluentMenuItemConstructor SetDescription(string description)
			{
				_item.Description = description;
				return this;
			}

			public FluentMenuItemConstructor SetAction(Action<Menu> action)
			{
				_item.Action = action;
				return this;
			}

			public FluentMenuConstructor EndNewItem()
			{
				_menuConstructor.AddItem(_item);
				return _menuConstructor;
			}

			#endregion
		}

		#region Variables

		private Menu _menu;

		#endregion

		#region Constructors

		public FluentMenuConstructor(Game game)
		{
			Game = game;
			_menu = new Menu(Game);
		}

		#endregion

		#region Properties

		private Game Game { get; set; }

		#endregion

		#region Methods

		public FluentMenuConstructor AddItem(MenuItem item)
		{
			_menu.Add(item);
			return this;
		}

		public FluentMenuItemConstructor BeginNewItem()
		{
			return new FluentMenuItemConstructor(this);
		}

		public Menu GetMenu()
		{
			return _menu;
		}

		#endregion
	}
}